package com.udp.nml;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class BasicDatagramClient 
{
	public static void main(String[] args)
	{
		try 
		{			
			// Create a socket that will send/receive via local port 1983.
			DatagramSocket socket = new DatagramSocket(1983);

			/**
			    // Create a byte array.
			    byte[] sendBuf = new byte[8];
				
				// Set byte 8 to 1.
				sendBuf[7] = 1;
			*/
			
			// Create an example String.
			String string = "Niall McLoughlin";
			
			// Get the byte array representing the name string.  
			byte[] sendBuf = string.getBytes();
			
			// Create an InetAddress representing the url where the UDP server is 
			// running (i.e. localhost)
			InetAddress address = InetAddress.getByName("localhost");
			
			// Create a Datagram Packet from the buffer, address and port.
			DatagramPacket packet = 
				new DatagramPacket(
					sendBuf, 
					sendBuf.length, 
			        address, 
			        UDPServer.PORT);
			
			// Send the DatagramPacket via the local port 1983.
			socket.send(packet);
		} 
		catch (UnknownHostException e) 
		{

		} 
		catch (IOException e) 
		{

		}
	}
}